package day7;

import java.util.Scanner;

public class BankAccount {
    private String account;
    private String password;
    private double money;

    public void setAccount(String account) {
        this.account = account;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public double getMoney() {
        return this.money;
    }

    public void addMoney(double money){
        this.money += money;
        System.out.println("存款成功");
        System.out.println("余额:" + this.money);
    }

    public boolean minusMoney(double money){
        if(this.money-money < 0){
            System.out.println("余额不足！！！");
            return false;
        }
        this.money -= money;
        System.out.println("余额:" + this.money);
        return true;
    }

    public BankAccount(String account, String password, double money){
        setAccount(account);
        setPassword(password);
        setMoney(money);
    }

    public boolean Verify(String account, String password){
        if ((this.account).equals(account) && (this.password).equals(password)) {
            return true;
        }
        return false;
    }
}

class TestBankAccount{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BankAccount ba=new BankAccount("abc","123456", 202516);
        for (int num=0;num<3;num++ ){
            System.out.println("******XXXX银行******");
            System.out.println("1.登录");
            System.out.println("2.退出");
            System.out.print("请输入编号:");
            if (sc.nextInt() == 1) {
                System.out.println("********************");
                System.out.print("请输入账号:");
                String account = sc.next();
                System.out.print("请输入密码:");
                String password = sc.next();
                if (ba.Verify(account, password)) {
                    break;
                } else {
                    System.out.println("账户或密码错误！！！"+"请重试");
                    System.out.println("您还有"+(3-num-1)+"机会");
                    if (num==2){
                        System.out.println("程序结束");
                        System.exit(0);
                    }
                }
            }
            else {
                System.out.println("程序结束");
                System.exit(0);
            }
        }
        int xz=0;
        while (xz!=4){
            System.out.println("******XXXX银行******");
            System.out.println("1.存款");
            System.out.println("2.取款");
            System.out.println("3.查询余额");
            System.out.println("4.退出");
            System.out.print("请输入编号:");
            xz = sc.nextInt();
            System.out.println("********************");
            switch (xz){
                case 1:
                    System.out.println("请输入存款金额:");
                    ba.addMoney(sc.nextDouble());
                    break;
                case 2:
                    System.out.println("请输入取款金额:");
                    if(ba.minusMoney(sc.nextDouble())){
                        System.out.println("取款成功");
                    }
                    else {
                        System.out.println("取款失败");
                    };
                    break;
                case 3:System.out.println("余额:"+ba.getMoney());
                    break;
                case 4:System.out.println("程序结束");System.exit(0);
            }
        }
    }
}

